#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1010;
int n, k;
int dp[N];
int re_dp[N];
int vec[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++)
        cin >> vec[i];

    int res = 0;
    // 正序
    for (int i = 1; i <= n; i ++ )
    {
        dp[i] = 1;
        for (int j = 1; j < i; j ++ )
            if (vec[i] > vec[j]) 
                dp[i] = max(dp[j] + 1, dp[i]);
    }

    for (int i = n; i >= 1; i -- )
    {
        re_dp[i] = 1;
        for (int j = n; j > i; j -- )
            if (vec[i] > vec[j])
                re_dp[i] = max(re_dp[j] + 1, re_dp[i]);
    }

    for (int i = 1; i <= n; i ++ )
        res = max(dp[i] + re_dp[i] - 1, res);
    cout << res << endl;
    return 0;
}